#pragma once

#include <iostream>
using namespace std;

template <class T >
struct ListNode
{
	ListNode(const T& val = T())
		:_next(nullptr)
		,_prev(nullptr)
		,_data(val)
	{}
	ListNode<T>* _next;
	ListNode<T>* _prev;
	T _data;
};

template <class T,class Ref,class Ptr>
class ListIterator
{
	typedef ListNode<T> Node;
	typedef ListIterator<T, Ref, Ptr> Self;
	
	Node* _node;

	ListIterator(Node* node)
		:_node(node)
	{}

	Self& operator++()
	{
		_node = _node->_next;
		return *this;
	}
	Self operator++(int)
	{
		Node* tmp(_node);
		_node = _node->_next;

		return tmp;
	}
};
template <class T>
class list
{
	typedef ListNode<T> Node;
public:
	list()
	{
		_head = new Node();
		_head->_next = _head;
		_head->_prev = _head;
	}
	void push_back(const T& x)
	{
		Node* newnode = new Node(x);

		Node* tail = _head->_prev;

		newnode->_prev = tail;
		newnode->_next = _head;

		tail->_next = newnode;
		_head->_prev = newnode;
	}
	void pop_back()
	{
		Node* del = _head->_prev;
		Node* prev = del->_prev;
		Node* next = del->_next;

		prev->_next = next;
		next->_prev = prev;

		delete del;
		
	}


private:
	Node* _head;
};